package acm;

import java.util.Scanner;

public class 最小乘积 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        for (int i=0;i<t;i++) {
            int n=in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            int sum=0, temp,xbl;
            for (int j = 0; j < n; j++) {
                a[j] = in.nextInt();
                xbl=j;
                for (int xb=j;xb>=0;xb--){
                    if (a[xbl]<a[xb]){
                        temp=a[xbl];
                        a[xbl]=a[xb];
                        a[xb]=temp;
                        xbl=xb;
                    }
                }
            }
            for (int j = 0; j < n; j++) {
                b[j] = in.nextInt();
                xbl=j;
                for (int xb=j;xb>=0;xb--){
                    if (b[xbl]>b[xb]){
                        temp=b[xbl];
                        b[xbl]=b[xb];
                        b[xb]=temp;
                        xbl=xb;
                    }
                }
            }
            for (int j=0;j<n;j++){
                sum=sum+(a[j]*b[j]);
            }
            System.out.println(sum);
        }
    }
}
